package com.ztjava.score.controller;

import com.jfinal.aop.Duang;
import com.ztjava.core.Constant;
import com.ztjava.core.annotation.ControllerClass;
import com.ztjava.core.base.BaseController;
import com.ztjava.core.client.member.ApiClient;
import com.ztjava.ext.auth.annotation.UserController;
import com.ztjava.ext.auth.annotation.UserMethod;
import com.ztjava.ext.auth.bean.AuthSession;
import com.ztjava.score.model.ScoreInfo;
import com.ztjava.score.service.ScoreService;

@ControllerClass(client=ApiClient.class,path="/score")
@UserController(portal=Constant.P_MEMBER)
public class SocreApiController extends BaseController{
	private static ScoreService scoreService = Duang.duang(ScoreService.class);
	
	@UserMethod
	public void getScore(){
		String code = getPara("code","");
		if(code.equals("")){
			renderError("code不能为空！");
			return;
		}
		AuthSession authSession = getAttr(Constant.AUTHSESSION);
		ScoreInfo scoreInfo = scoreService.getUserScoreInfo(authSession.getId(), code);
		if(scoreInfo==null){
			renderError("不存在的积分类型！");
			return;
		}
		setAttr("score", scoreInfo.getInt("score"));
		setAttr(Constant.RESULT, Constant.SUCCESS);
		setAttr(Constant.MESSAGE, "操作成功！");
		renderJson(new String[]{Constant.RESULT,Constant.MESSAGE,"score"});
	}
}
